package cn.itsource.pet.controller;


import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.util.GetUserInfoUtil;
import cn.itsource.basic.util.PageList;
import cn.itsource.basic.util.RedisService;

import cn.itsource.pet.domain.SearchMasterMessage;
import cn.itsource.pet.domain.SearchMasterMessageQuery;
import cn.itsource.pet.service.SearchMasterMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("searchmasterMessage")
public class SearchMasterMessageController {
    @Autowired
    RedisService redisService;
    @Autowired
    SearchMasterMessageService service;

    @PostMapping("/publish")
    public AjaxResult publish(@RequestBody SearchMasterMessage message, HttpServletRequest request){
        Long userId = GetUserInfoUtil.getUserId();
        message.setUserId(userId);
        service.insert(message);

        return AjaxResult.me();
    }
    /**
     * /searchmaster/pagelist
     * 这里是寻主审核的分页查询
     */
    @PostMapping("/pagelist")
    public AjaxResult pagelist(@RequestBody SearchMasterMessageQuery query, HttpServletRequest request){
        Long shopId = GetUserInfoUtil.getShopId();

        PageList<SearchMasterMessage> messages = service.pagelist(query,shopId);

        return AjaxResult.setResult(messages);
    }

    @PostMapping("order")
    public AjaxResult order(@RequestBody SearchMasterMessage message){
        return service.order(message);
    }
}
